const express = require('express')
const crypto = require('crypto')
const config = require('../config')
const router = express.Router()
router.get('/wx', (req, res) => {
    const query = req.query
    console.log(query);
    const signature = query.signature
    const timestamp = query.timestamp
    const nonce = query.nonce
    const echostr = query.echostr
    const dataArry = new Array(config.Token, timestamp, nonce)
    dataArry.sort()
    const tempStr = dataArry.join('')
    const hashCode = crypto.createHash('sha1')
    const resCode = hashCode.update(tempStr, 'utf8').digest('hex')
    if (resCode === signature) {
        res.send(echostr)
    } else {
        res.send('token验证失败')
    }
})

module.exports = router